{% extends 'my/layout.html.twig' %}

{% block title %}{{'my.learning.homework'|trans}} - {{ parent() }}{% endblock %}

{% set side_nav = 'my-homework' %}

{% block main %}
  <div class="panel panel-default panel-col">
    <div class="panel-heading">{{'my.learning.homework'|trans}}</span></div>
    <div class="panel-body">
      <ul class="nav nav-pills mb15">
        <li class="{% if status == 'finished' %}active{% endif %}"><a href="{{ path('my_homework_list',{status:'finished'}) }}">{{'my.learning.homework.check_finish'|trans}}</a></li>
        <li class="{% if status == 'reviewing' %}active{% endif %}"><a href="{{ path('my_homework_list',{status:'reviewing'}) }}">{{'my.learning.homework.check_reviewing'|trans}}</a></li>
      </ul>

      {% if answerRecords %}
        <table class="table table-striped table-hover">
          <tbody>
            {% for answerRecord in answerRecords %}
              {% set assessment = assessments[answerRecord.assessment_id]|default(null) %}
              {% set activity = activities[homeworkActivities[answerRecord['answer_scene_id']]['id']]|default(null) %}
              {% set task = tasks[activity.id]|default(null) %}
              {% set course = courses[task.courseId]|default(null) %}
              {% set answerReport = answerReports[answerRecord['answer_report_id']]|default(null) %}
              <tr>
                <td width="55%">
                  {{ task.title|default(assessment.name)|plain_text(60) }}
                  <div>
                    <small class="color-gray">
                      {{ 'come.from'|trans }}<a class="link-primary" href="{{ path('course_show',{id:course.id}) }}" target="_blank">《{{get_formated_course_title(course)}}》</a>
                    </small>
                    <small class="color-gray mhs">•</small>
                    <small class="color-gray" title="{{'my.learning.homework.begin_time'|trans}}">{{ answerRecord.begin_time|date('site.date_format'|trans) }}</small>
                  </div>
                </td>

                <td class="vertical-middle">
                  {% if answerRecord.status == 'reviewing' %}
                    <span class="color-warning">{{'my.learning.homework.checking'|trans}}</span>
                  {% elseif answerRecord.status == 'finished' %}
                    <span class="color-gray">
                      {{'my.learning.homework.right_question_count'|trans({'%rightItemCount%': answerReport.right_question_count})|raw}}
                      {% if assessment %}{{'my.learning.homework.total_questions_count'|trans({'%itemCount%': assessment.question_count})|raw}}{% endif %}
                    </span>
                  {% else %}
                    <span class="color-gray">{{'my.learning.homework.uncommit'|trans}}</span>
                  {% endif %}
                </td>
                <td class="vertical-middle">
                  {% if answerRecord.status in ['doing', 'paused'] %}
                    <a href="{{ path('course_task_show',{courseId:answerRecord.courseId,id:task.id}) }}" class="btn btn-default btn-sm">{{'my.learning.homework.continue_do'|trans}}</a>
                  {% elseif answerRecord.status == 'finished' and assessment %}
                    <a href="{{ path('homework_result_show',{answerRecordId:answerRecord.id,action:'my'}) }}" class="color-primary" target="_blank">{{'my.learning.homework.show_result'|trans}}</a>
                  {% endif %}
                </td>
              </tr>
            {% endfor %}

          </tbody>
        </table>
        {{ web_macro.paginator(paginator) }}
      {% else %}
        <div class="empty">{{'my.learning.homework.empty'|trans}}</div>
      {% endif %}
    </div>
  </div>

{% endblock %}
